package com.kinghood.infrastructure.util;


import com.kinghood.infrastructure.model.principal.KingHoodUser;

import java.util.Objects;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2023-12-20 18:09
 **/
public class UserUtil {

    private static ThreadLocal<KingHoodUser> user = new ThreadLocal<>();

    public static void setUser(KingHoodUser in){
        user.set(in);
    }

    public static KingHoodUser getUser(){
        return user.get();
    }

    public static Long getUserId(){
        KingHoodUser user = getUser();
        if(Objects.nonNull(user)){
            return user.getId();
        }
        return null;
    }

    public static void remove(){
        user.remove();
    }
}
